home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UTIL / MEMORY / VIRTUASRC / !Virtual / c / lib < prev    next >
Text File  |  1993-09-06  |  1KB  |  80 lines

  1. /*
  2.  * lib.c
  3.  * Part of the !Virtual distribution
  4.  * (c) bdb/nas/fo, 1992-3
  5.  */
  6.  
  7. #include "swis.h"
  8. #include "swiv.h"
  9.  
  10. #include "lib.h"
  11.  
  12. void strcpy(char *p,char *q)
  13. {
  14. while ((*p++=*q++)!=0)
  15.   ;
  16. }
  17.  
  18. void memcpy(char *p, char *q, int n)
  19. {
  20. while (n-->0)
  21.   *p++=*q++;
  22. }
  23.  
  24. int strlen( char *p )
  25. {
  26.   int n=0;
  27.   while (*p++)
  28.     n++;
  29.   return n;
  30. }
  31.  
  32. int xtoi( char *p )
  33. {
  34.   int v=0;
  35.   if (swix(OS_ReadUnsigned,IN(R0|R1)|OUT(R2),16,p,&v))
  36.     return 0;
  37.   return v;
  38. }
  39.  
  40. int sizetoi( char *p )
  41. {
  42.   int v=0;
  43.   if (swix(OS_ReadUnsigned,IN(R0|R1)|OUT(R1|R2),10,p,&p,&v))
  44.     return 0;
  45.   if (*p=='K' || *p=='k')
  46.     v*=1024;
  47.   if (*p=='M' || *p=='m')
  48.     v*=1024*1024;
  49.   return v;
  50. }
  51.  
  52. void *alloc(int size)
  53.   void *addr;
  54.   swi(OS_Module, IN(R0|R3)|OUT(R2), 6, size, &addr);
  55.   return addr;
  56. }
  57.  
  58. void free(void *addr)
  59. {
  60.   if (addr)
  61.     swi(OS_Module, IN(R0|R2), 7, addr);
  62. }
  63.  
  64. #ifndef print_f
  65. #define print_f 0xBe00
  66. #endif
  67.  
  68. void printf(char *format,...)
  69. {
  70.   int *a=(int *)&format+1;
  71.   swi(print_f,IN(R0|R1|R2|R3|R4|R5|R6|R7|R8),format,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
  72. }
  73.  
  74. void _printf(char *format,...)
  75. {
  76.   int *a=(int *)&format+1;
  77.   swi(print_f,IN(R0|R1|R2|R3|R4|R5|R6|R7|R8),format,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
  78. }
  79.